﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.BackgroundAudio;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Radio;

namespace DoubanRadio
{
    public class DoubanHelper : IRadioHelper
    {
        public List<AudioTrack> GetDataFromString(string content)
        {
            List<AudioTrack> at = new List<AudioTrack>();
            Content __content =new Content();
            string res = content.ToString().Replace(@"\", "").Replace("'", "(@#@)").Replace("\"", "'");
            JsonSerializer serializer = new JsonSerializer();
            JObject o = JObject.Parse(res);
            __content = serializer.Deserialize(new JTokenReader(o), typeof(Content)) as Content;
            foreach (var s in __content.song)
            {
                AudioTrack a = new AudioTrack(new Uri(s.url, UriKind.Absolute), s.title.Replace("(@#@)", "'"), s.artist.Replace("(@#@)", "'"), s.albumtitle.Replace("(@#@)", "'"), new Uri(s.picture, UriKind.Absolute));
                at.Add(a);
            }
            return at;
        }
    }
}
